<template>
	<web-view :src="webUrl" :webview-styles="webviewStyles"></web-view>
</template>

<script>
	export default {
		data() {
			return {
				webUrl: getApp().globalData.WebUrl + 'carryUserDetail.html#/carryUserHealthCard',
				webviewStyles: {
					progress: {
						color: '#FF3333',
					},
				},
				carriedUserid: ''
			}
		},
		onLoad(option) {
			if (option && option.carriedUserid) {
				this.carriedUserid = option.carriedUserid
			}
		},
		onShow() {
			let carriedUserid = this.carriedUserid
			let user_id = uni.getStorageSync('user_id')
			let access_token = uni.getStorageSync('access_token')
			let open_id = uni.getStorageSync('open_id')
			const pages = getCurrentPages()
			const currentPage = pages[pages.length - 1]
			const currentPath = currentPage.route
			//console.log('小程序当前页面路径:', currentPath)
			let queryData = {}
			if (carriedUserid) {
				queryData = {
					carriedUserid,
					user_id,
					access_token,
					open_id,
					currentPath,
					time: new Date().getTime(),
				}
			}

			let pathParams = ''
			if (
				typeof queryData === 'object' &&
				queryData !== null &&
				!Array.isArray(queryData) &&
				Object.keys(queryData).length > 0
			) {
				for (let key in queryData) {
					pathParams += key + '=' + queryData[key] + '&'
				}
				pathParams = pathParams.slice(0, pathParams.length - 1)
			}

			let urlPath = this.webUrl;
			if (this.webUrl.indexOf('?') !== -1) {
				urlPath = this.webUrl.split('?')[0]
			}
			this.webUrl = urlPath + '?' + pathParams
			//console.log('h5路径:', this.webUrl)
		}
	}
</script>